package com.yuncheng.spcyApi.spcy;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yuncheng.spcyApi.alog.annotation.Log;
import com.yuncheng.spcyApi.alog.utils.IpUtils;
import com.yuncheng.spcyApi.busService.BusService;
import com.yuncheng.spcyApi.constant.jcy.JcydjbConstant;
import com.yuncheng.spcyApi.constant.common.SpcyCommonConstant;
import com.yuncheng.spcyApi.constant.common.SpcyConstant;
import com.yuncheng.spcyApi.entity.*;
import com.yuncheng.exception.BusinessException;
import com.yuncheng.spcyApi.mapper.SpcySqsxXpjlMapper;
import com.yuncheng.spcyApi.mapper.SpcySqsxYbmjlMapper;
import com.yuncheng.spcyApi.service.*;
import com.yuncheng.spcyApi.spcyService.SpcyMyInfoService;
import com.yuncheng.spcyApi.spcyService.SpcyYbmjhService;
import com.yuncheng.spcyApi.utils.*;
import com.yuncheng.spcyApi.vo.common.HttpResultVo;
import com.yuncheng.spcyApi.vo.common.PageVo;
import com.yuncheng.spcyApi.vo.common.Result;
import com.yuncheng.spcyApi.vo.jcy.HcyXpVo;
import com.yuncheng.spcyApi.vo.spcy.MyYbmListVo;
import com.yuncheng.spcyApi.vo.sqsx.SqsxYbmjbxxVo;
import com.yuncheng.spcyApi.vo.sqsx.YbmHcyListVo;
import com.yuncheng.vo.HttpResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.beanutils.ConvertUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.context.annotation.Lazy;
import org.springframework.web.bind.annotation.*;
import utils.DateConversionUtils;

import javax.annotation.Resource;
import java.lang.reflect.InvocationTargetException;
import java.util.*;

/**
 * @author hua
 */
@Api(tags = "申请事项-预报名计划")
@RestController
@RequestMapping("/api/spzx-spcy/ybmjh")
public class SpcySqsxYbmjhController {

    @Resource
    private ISpcySqsxYbmjbxxService spcySqsxYbmjbxxService;

    @Resource
    private ISpcySqsxYbmjhService spcySqsxYbmjhService;

    @Resource
    private ISpcySqsxYbmjlService spcySqsxYbmjlService;

    @Resource
    private ISpcySqsxBaiscService spcySqsxBaiscService;

    @Resource
    private ISpcyRsHcyService spcyRsHcyService;

    @Resource
    private SpcySqsxYbmjlMapper spcySqsxYbmjlMapper;

    @Resource
    private ISpcySqsxXptjjlService spcySqsxXptjjlService;

    @Resource
    private IYcSysUserService sysUserService;

    @Resource
    @Lazy
    private BusService busService;

    @Resource
    @Lazy
    private SpcyYbmjhService spcyYbmjhService;

    @Resource
    private SpcySqsxXpjlMapper spcySqsxXpjlMapper;

    @Resource
    private SpcyMyInfoService spcyMyInfoService;


//    @Log(title = "报名计划管理-分页查询")
//    @ApiOperation(value = "报名计划管理-分页查询")
    @GetMapping(value = "bmjhglPageList")
    public HttpResult bmjhglPageList(SpcySqsxYbmjh query,
                                     @RequestParam(value = "kssjStart",defaultValue = "") String kssjStart,
                                     @RequestParam(value = "kssjEnd",defaultValue = "") String kssjEnd,
                                     @RequestParam(value = "jssjStart",defaultValue = "") String jssjStart,
                                     @RequestParam(value = "jssjEnd",defaultValue = "") String jssjEnd,
                                     PageVo pageVo){
        Page<SpcySqsxYbmjh> page = new Page<>(pageVo.getPageNo(), pageVo.getPageSize());

        LambdaQueryWrapper<SpcySqsxYbmjh> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(StringUtils.isNotBlank(query.getFbmzt()), SpcySqsxYbmjh::getFbmzt, query.getFbmzt());
        queryWrapper.eq(StringUtils.isNotBlank(query.getFjcylx()), SpcySqsxYbmjh::getFjcylx, query.getFjcylx());
        queryWrapper.like(StringUtils.isNotBlank(query.getFjcbmrwmc()), SpcySqsxYbmjh::getFjcbmrwmc, query.getFjcbmrwmc());
        queryWrapper.like(StringUtils.isNotBlank(query.getFjcyq()), SpcySqsxYbmjh::getFjcyq, query.getFjcyq());
        if (query.getFjcts() != null){
            queryWrapper.ge(SpcySqsxYbmjh::getFjcts, query.getFjcts());
        }

        if (StringUtils.isNotBlank(kssjStart)){
            queryWrapper.ge(SpcySqsxYbmjh::getFcykssj, DateConversionUtils.convertStringToDateYmd(kssjStart));
        }
        if (StringUtils.isNotBlank(kssjEnd)){
            queryWrapper.le(SpcySqsxYbmjh::getFcykssj, DateConversionUtils.convertStringToDateYmd(kssjEnd));
        }

        if (StringUtils.isNotBlank(jssjStart)){
            queryWrapper.ge(SpcySqsxYbmjh::getFcyjssj, DateConversionUtils.convertStringToDateYmd(jssjStart));
        }
        if (StringUtils.isNotBlank(jssjEnd)){
            queryWrapper.le(SpcySqsxYbmjh::getFcyjssj, DateConversionUtils.convertStringToDateYmd(jssjEnd));
        }

        queryWrapper.orderByAsc(SpcySqsxYbmjh::getFfbrq);
        Page<SpcySqsxYbmjh> pageList = spcySqsxYbmjhService.page(page, queryWrapper);

        return HttpResult.ok(pageList);
    }

    @Log(title = "可报名计划-分页查询")
    @ApiOperation(value = "可报名计划-分页查询")
    @GetMapping(value = "kbmjhPageList")
    public HttpResult kbmjhPageList(MyYbmListVo query,
                                    @RequestParam(value = "kssjStart",defaultValue = "") String kssjStart,
                                    @RequestParam(value = "kssjEnd",defaultValue = "") String kssjEnd,
                                    @RequestParam(value = "jssjStart",defaultValue = "") String jssjStart,
                                    @RequestParam(value = "jssjEnd",defaultValue = "") String jssjEnd,
                                    PageVo pageVo){

        // 将报名截止日期的数据更新为已结束
        spcySqsxYbmjlMapper.updateYbmjhByFbmjsrq(DateConversionUtils.DateToStringYYYYMMDD(new Date()),
                SpcyCommonConstant.SQSX_YBMJH_BMZT_BMZ, SpcyCommonConstant.SQSX_YBMJH_BMZT_YJS);

        Page<MyYbmListVo> page = new Page<>(pageVo.getPageNo(), pageVo.getPageSize());

        // 查询报名日期大于当前日期
        String nowDate = null;

        String nowUserId = GetCurrentUserUtils.getCurrentUserId();

        // 验证是否已解聘
        if (sysUserService.verifyUserFgzztIsJp(nowUserId)){
            return HttpResult.ok();
        }

        query.setCxfbzt(SpcyCommonConstant.SQSX_YBMJH_BMZT_WKS);
        query.setCxjclx("是");
        Page<MyYbmListVo> pageList = spcySqsxYbmjlMapper.getYbmJhPageList(page, query, kssjStart, kssjEnd, jssjStart, jssjEnd, nowDate, nowUserId);

        /** 2020628 */
        /*List<MyYbmListVo> records = pageList.getRecords();
        if (CollectionUtil.isNotEmpty(records)){
            for (MyYbmListVo bean : records){
                List<SpcySqsxYbmjl> bmList = spcySqsxYbmjlService.list(new LambdaQueryWrapper<SpcySqsxYbmjl>()
                        .eq(SpcySqsxYbmjl::getFbmjhid, bean.getId())
                        .eq(SpcySqsxYbmjl::getFuserid, nowUserId));
                if (CollectionUtil.isEmpty(bmList)){
                    bean.setSfbm("未报名");
                }else {
                    bean.setSfbm("已报名");
                }
            }
        }
        pageList.setRecords(records);*/

        return HttpResult.ok(pageList);
    }

    @Log(title = "APP角标-检查任务预报名及检查员考评")
    @ApiOperation(value = "APP角标-检查任务预报名及检查员考评")
    @GetMapping(value = "appJbCount")
    public HttpResult appJbCount() {
        String nowUserId = GetCurrentUserUtils.getCurrentUserId();

        Map resultMap = new HashMap<>();

        // 验证是否已解聘
        if (sysUserService.verifyUserFgzztIsJp(nowUserId)) {
            resultMap.put("ybmCount", 0);
        } else{
            MyYbmListVo query = new MyYbmListVo();
            query.setCxfbzt(SpcyCommonConstant.SQSX_YBMJH_BMZT_WKS);
            query.setCxjclx("是");
            Page<MyYbmListVo> pageList = spcySqsxYbmjlMapper.getYbmJhPageList(new Page<>(1, 10), query, null, null, null, null, null, nowUserId);

            resultMap.put("ybmCount", pageList.getTotal());
        }


        resultMap.put("jcgzkhCount", spcyMyInfoService.getMyKpDbsl(nowUserId));
        return HttpResult.ok(resultMap);
    }

//    @Log(title = "报名计划-添加-根据申请事项id")
//    @ApiOperation(value = "报名计划-添加-根据申请事项id")
    @PostMapping(value = "addBmjh")
    public HttpResult addBmjh(@RequestBody SpcySqsxYbmjh bean){
        if (StringUtils.isBlank(bean.getSqsxid())){
            throw new BusinessException("参数为空！");
        }

        List<SpcySqsxYbmjh> list = spcySqsxYbmjhService.list(new LambdaQueryWrapper<SpcySqsxYbmjh>()
                .eq(SpcySqsxYbmjh::getSqsxid, bean.getSqsxid()));
        if (CollectionUtil.isNotEmpty(list)){
            throw new BusinessException("已经存在过报名计划，无法再次发起报名！");
        }

        bean.setId(GetUuIdUtils.ReplaceUuId());

        SpcySqsxBasic sqsx = spcySqsxBaiscService.selectSqsxById(bean.getSqsxid());
        if (sqsx == null){
            throw new BusinessException("没有相匹配的数据！");
        }

        if (sqsx.getFcykssj() == null || sqsx.getFcyjssj() == null) {
            throw new BusinessException("请先选择检查时间并保存！");
        }

        int jcts = 0;
        if (sqsx.getFcyjssj() != null && sqsx.getFcykssj() != null) {
            jcts = (int) DateUtil.between(sqsx.getFcykssj(), sqsx.getFcyjssj(), DateUnit.DAY) + 1;
        }
        bean.setFjcts(jcts);
        bean.setFcykssj(sqsx.getFcykssj());
        bean.setFcyjssj(sqsx.getFcyjssj());
        bean.setFjcylx(JcydjbConstant.getJcylxByYwflcode(sqsx.getFywflcode()));
        bean.setFbmzzrs(0);
        bean.setFbmzyrs(0);
        bean.setFbmybrs(0);

        bean.setFbmzt(SpcyCommonConstant.SQSX_YBMJH_BMZT_BMZ);
        bean.setFfbrid(GetCurrentUserUtils.getCurrentUserId());
        bean.setFfbrq(new Date());
        bean.setFfbrxm(GetCurrentUserUtils.getCurrentUserName());
        spcySqsxYbmjhService.save(bean);

        return HttpResultVo.HttpResultSave(bean.getId(), "保存成功");
    }

    @Log(title = "点击报名")
    @ApiOperation(value = "点击报名")
    @GetMapping(value = "djbm")
    public HttpResult djbm(@RequestParam(value = "id",defaultValue = "")String id){

        // 接口限流
        if (!IpRateLimiterUtils.tryAcquire(GetCurrentUserUtils.getCurrentUserId())){
            return HttpResult.error("访问过于频繁，请稍候再试！");
        }

        if (StringUtils.isBlank(id)){
            return HttpResult.error("参数为空！");
        }

        SpcySqsxYbmjh jh = spcySqsxYbmjhService.getById(id);
        if (jh == null){
            return HttpResult.error("没有相匹配的数据！");
        }

        if (StringUtils.isBlank(jh.getFbmzt()) || !jh.getFbmzt().equals(SpcyCommonConstant.SQSX_YBMJH_BMZT_BMZ)){
            return HttpResult.error("当前报名已结束！");
        }

        String userid = GetCurrentUserUtils.getCurrentUserId();

        /** 验证是否已经报名 */
        List<SpcySqsxYbmjl> bmList = spcySqsxYbmjlService.list(new LambdaQueryWrapper<SpcySqsxYbmjl>()
                .eq(SpcySqsxYbmjl::getFbmjhid, id)
                .eq(SpcySqsxYbmjl::getFuserid, userid));
        if (CollectionUtil.isNotEmpty(bmList)){
            return HttpResult.error("当前已经报名了！");
        }

        List<SpcyRsHcy> jcyList = spcyRsHcyService.selectJcyYxListByFlx(userid, jh.getFjcylx());
        if (CollectionUtil.isEmpty(jcyList)){
            return HttpResult.error("没有符合的检查类型！");
        }
        String jcyid = jcyList.get(0).getId();

        SpcySqsxYbmjl jl = new SpcySqsxYbmjl();
        jl.setId(GetUuIdUtils.ReplaceUuId());
        jl.setFbmjhid(id);
        jl.setFuserid(userid);
        jl.setFjcyid(jcyid);
        jl.setFsqsxid(jh.getSqsxid());
        jl.setFbmsj(new Date());
        jl.setFxpzt(SpcyCommonConstant.SQSX_YBMJL_XPZT_WXP);
        spcySqsxYbmjlService.save(jl);

        /*
        String fssk = jcyList.get(0).getFssk();
        int bmzzrs = jh.getFbmzzrs();
        int bmzyrs = jh.getFbmzyrs();
        int bmybrs = jh.getFbmybrs();
        if (fssk.equals(SpcyConstant.HCY_SSK_ZZ)){
            bmzzrs = bmzzrs + 1;
            jh.setFbmzzrs(bmzzrs);

        }else if (fssk.equals(SpcyConstant.HCY_SSK_ZY)){
            bmzyrs = bmzyrs + 1;
            jh.setFbmzyrs(bmzyrs);

        }else if (fssk.equals(SpcyConstant.HCY_SSK_YB)){
            bmybrs = bmybrs + 1;
            jh.setFbmybrs(bmybrs);

        }

        // 满足所有条件结束
        if (jh.getFzzrs() == bmzzrs && jh.getFzyrs() == bmzyrs && jh.getFybrs() == bmybrs){
            jh.setFbmzt(SpcyCommonConstant.SQSX_YBMJH_BMZT_BMRSYM);
        }

        spcySqsxYbmjhService.updateById(jh);
        */

        return HttpResult.ok("报名成功");
    }

    @Log(title = "取消报名")
    @ApiOperation(value = "取消报名")
    @GetMapping(value = "cancelBm")
    public HttpResult cancelBm(@RequestParam(value = "id",defaultValue = "")String id){
        if (StringUtils.isBlank(id)){
            return HttpResult.error("参数为空！");
        }

        /** 取消已经报名 */
        spcySqsxYbmjlService.remove(new LambdaQueryWrapper<SpcySqsxYbmjl>()
                .eq(SpcySqsxYbmjl::getFbmjhid, id)
                .eq(SpcySqsxYbmjl::getFuserid, GetCurrentUserUtils.getCurrentUserId()));


        return HttpResult.ok("取消成功");
    }

//    @Log(title = "结束报名")
//    @ApiOperation(value = "结束报名")
    @GetMapping(value = "jsbm")
    public HttpResult jsbm(@RequestParam(value = "sqsxid",defaultValue = "")String sqsxid){
        if (StringUtils.isBlank(sqsxid)){
            throw new BusinessException("事项参数为空！");
        }
        LambdaUpdateWrapper<SpcySqsxYbmjh> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.eq(SpcySqsxYbmjh::getSqsxid, sqsxid);

        SpcySqsxYbmjh updateBean = new SpcySqsxYbmjh();
        updateBean.setFbmzt(SpcyCommonConstant.SQSX_YBMJH_BMZT_YJS);

        spcySqsxYbmjhService.update(updateBean, updateWrapper);

        return HttpResult.ok("结束成功");
    }

//    @Log(title = "申请事项-预报名状态")
//    @ApiOperation(value = "申请事项-预报名状态")
    @GetMapping(value = "verifySqsxYbmzt")
    public HttpResult verifySqsxYbmzt(@RequestParam(value = "sqsxid",defaultValue = "OAOCSS")String sqsxid){

        String flag = "0";
        List<SpcySqsxYbmjh> list = spcySqsxYbmjhService.list(new LambdaQueryWrapper<SpcySqsxYbmjh>()
                .eq(SpcySqsxYbmjh::getSqsxid, sqsxid));
        if (CollectionUtil.isNotEmpty(list)){
            if (list.get(0).getFbmzt().equals(SpcyCommonConstant.SQSX_YBMJH_BMZT_BMZ)){
                flag = "1";
            }else {
                flag = "2";
            }
        }

        return HttpResultVo.HttpResultSave(flag);
    }

    @Log(title = "验证当前人员是否已经报名")
    @ApiOperation(value = "验证当前人员是否已经报名")
    @GetMapping(value = "verifySfyjbm")
    public HttpResult verifySfyjbm(@RequestParam(value = "id",defaultValue = "")String id){
        if (StringUtils.isBlank(id)){
            return HttpResult.error("参数为空！");
        }

        String flag = "0"; // 未报名
        List<SpcySqsxYbmjl> bmList = spcySqsxYbmjlService.list(new LambdaQueryWrapper<SpcySqsxYbmjl>()
                .eq(SpcySqsxYbmjl::getFbmjhid, id)
                .eq(SpcySqsxYbmjl::getFuserid, GetCurrentUserUtils.getCurrentUserId()));
        if (CollectionUtil.isNotEmpty(bmList)){
            flag = "1";  // 已经报名
        }

        return HttpResultVo.HttpResultSave(flag);
    }

//    @Log(title = "申请事项-报名信息")
//    @ApiOperation(value = "申请事项-报名信息")
    @GetMapping(value = "queryBmxmBySqsx")
    public HttpResult queryBmxmBySqsx(@RequestParam(value = "sqsxid",defaultValue = "OAOCSS")String sqsxid){

        List<SpcySqsxYbmjh> list = spcySqsxYbmjhService.list(new LambdaQueryWrapper<SpcySqsxYbmjh>()
                .eq(SpcySqsxYbmjh::getSqsxid, sqsxid));
        if (CollectionUtil.isNotEmpty(list)){
            return HttpResult.ok(list.get(0));
        }

        return HttpResult.ok(new SpcySqsxYbmjh());
    }

    @Log(title = "获取预报名人员列表-根据id")
    @ApiOperation(value = "获取预报名人员列表-根据id")
    @GetMapping(value = "queryYbmRyListById")
    public HttpResult queryYbmRyListById(YbmHcyListVo query){
        if (StringUtils.isNotBlank(query.getId())){
            query.setFbmjhid(query.getId());
            query.setId(null);
        }else {
            query.setFbmjhid("OAOCSS");
        }
        List<YbmHcyListVo> list = spcySqsxYbmjlMapper.getYbmHcyList(query);

        return HttpResultVo.HttpResultList(list);
    }

    @Log(title = "获取预报名人员列表-根据申请事项id")
    @ApiOperation(value = "获取预报名人员列表-根据申请事项id")
    @GetMapping(value = "queryYbmRyList")
    public HttpResult queryYbmRyList(YbmHcyListVo query){
        if (StringUtils.isBlank(query.getSqsxid())){
            query.setSqsxid("OAOCSS");
        }
        List<YbmHcyListVo> list = spcySqsxYbmjlMapper.getYbmHcyList(query);

        return HttpResultVo.HttpResultList(list);
    }

    @Log(title = "查看报名信息-根据id")
    @ApiOperation(value = "查看报名信息-根据id")
    @GetMapping(value = "queryBmxxById")
    public HttpResult queryBmxxById(@RequestParam(value = "id",defaultValue = "")String id){
        SpcySqsxYbmjh bean = spcySqsxYbmjhService.getById(id);

        return HttpResult.ok(bean);
    }

    @Log(title = "获取抽选条件记录-根据申请事项id")
    @ApiOperation(value = "获取抽选条件记录-根据申请事项id")
    @GetMapping(value = "queryXptjjlList")
    public HttpResult queryXptjjlList(@RequestParam(value = "sqsxid",defaultValue = "OAOCSS")String sqsxid){

        List<SpcySqsxXptjjl> list = spcySqsxXptjjlService.getXptjjlListBySqsxId(sqsxid);
        return HttpResultVo.HttpResultList(list);
    }

//    @Log(title = "预报名检查员自动选派")
//    @ApiOperation(value = "预报名检查员自动选派")
    @GetMapping(value = "ybmJcyXpByAuto")
    public HttpResult<?> ybmJcyXpByAuto(YbmHcyListVo hcyXpVo){
        if (StringUtils.isBlank(hcyXpVo.getSqsxid())){
            return HttpResult.error("申请事项参数为空！");
        }

        String sqsxid = hcyXpVo.getSqsxid();
        String fywflcode = hcyXpVo.getFywflcode();
        String fssqy = hcyXpVo.getFssqy();
        String fusertype = hcyXpVo.getFusertype();
        String zytc = hcyXpVo.getZytc();
        String hbqy = hcyXpVo.getHbqy();
        String kssj = hcyXpVo.getKssj();
        String jssj = hcyXpVo.getJssj();

        Integer fzzrs = hcyXpVo.getFzzrs();
        Integer fzyrs = hcyXpVo.getFzyrs();
        Integer fybrs = hcyXpVo.getFybrs();

        if (StringUtils.isBlank(fusertype)){
            fusertype = SpcyConstant.HCY_USERTYPE_JCY;
        }

        /** 初始化选派条件记录 */
        HcyXpVo xptjVo = new HcyXpVo();
        xptjVo.setHbqy(hbqy);
        xptjVo.setZytc(zytc);
        xptjVo.setFzzrs(fzzrs);
        xptjVo.setFzyrs(fzyrs);
        xptjVo.setFybrs(fybrs);
        xptjVo.setFsmszt(hcyXpVo.getFsmszt());
        xptjVo.setFdqrdxnr(hcyXpVo.getFdqrdxnr());
        String fxptjid = GetUuIdUtils.ReplaceUuId();
        spcySqsxXptjjlService.initXptjjl(fxptjid, sqsxid, SpcyConstant.XPTJ_XPFS_YBMSJ, xptjVo, 0, 0, 0, "");


        StringBuffer errorMsg = new StringBuffer();
        if (fzzrs > 0){
            Result result = busService.ybmJcyXpByAuto(hcyXpVo, sqsxid, SpcyConstant.HCY_SSK_ZZ, fusertype, zytc, hbqy, fssqy, fywflcode, kssj, jssj, fzzrs, fzyrs, fybrs, fxptjid);
            if (!result.isSuccess()) {
                errorMsg.append(result.getMessage());
            }
        }

        if (fzyrs > 0){
            Result result = busService.ybmJcyXpByAuto(hcyXpVo, sqsxid, SpcyConstant.HCY_SSK_ZY, fusertype, zytc, hbqy, fssqy, fywflcode, kssj, jssj, fzzrs, fzyrs, fybrs, fxptjid);
            if (!result.isSuccess()) {
                errorMsg.append(result.getMessage());
            }
        }

        if (fybrs > 0){
            Result result = busService.ybmJcyXpByAuto(hcyXpVo, sqsxid, SpcyConstant.HCY_SSK_YBK, fusertype, zytc, hbqy, fssqy, fywflcode, kssj, jssj, fzzrs, fzyrs, fybrs, fxptjid);
            if (!result.isSuccess()) {
                errorMsg.append(result.getMessage());
            }
        }

        if (!StringPatternUtils.verifryIsEmptyStringBuffer(errorMsg)){
            return HttpResult.error(errorMsg.toString());
        }

        return HttpResult.ok("操作成功");
    }

    @Log(title = "预报名+检查员库检查员自动选派")
    @ApiOperation(value = "预报名+检查员库检查员自动选派")
    @GetMapping(value = "ybmOrJcyXpByAuto")
    public HttpResult<?> ybmOrJcyXpByAuto(YbmHcyListVo hcyXpVo){
        if (StringUtils.isBlank(hcyXpVo.getSqsxid())){
            return HttpResult.error("申请事项参数为空！");
        }

        if (hcyXpVo.getBlMax() == null){
            hcyXpVo.setBlMax(3);
        }
        String sqsxid = hcyXpVo.getSqsxid();
        String fywflcode = "";
        String fssqy = hcyXpVo.getFssqy();
        String fusertype = SpcyConstant.HCY_USERTYPE_JCY;

        String zytc = hcyXpVo.getZytc();
        String hbqy = hcyXpVo.getHbqy();
        String kssj = hcyXpVo.getKssj();
        String jssj = hcyXpVo.getJssj();

        Integer fzzrs = hcyXpVo.getFzzrs();
        Integer fzyrs = hcyXpVo.getFzyrs();
        Integer fybrs = hcyXpVo.getFybrs();

        SpcySqsxBasic sqsx = spcySqsxBaiscService.selectSqsxInfoById(sqsxid);
        if (sqsx == null){
            return HttpResult.error("没有相匹配的事项数据！");
        }

        /** 初始化选派条件记录 */
        HcyXpVo xptjVo = new HcyXpVo();
        xptjVo.setHbqy(hbqy);
        xptjVo.setZytc(zytc);
        xptjVo.setFzzrs(fzzrs);
        xptjVo.setFzyrs(fzyrs);
        xptjVo.setFybrs(fybrs);
        xptjVo.setFsmszt(hcyXpVo.getFsmszt());
        xptjVo.setFdqrdxnr(hcyXpVo.getFdqrdxnr());
        String fxptjid = GetUuIdUtils.ReplaceUuId();
        spcySqsxXptjjlService.initXptjjl(fxptjid, sqsxid, SpcyConstant.XPFS_ZDXZ, xptjVo, 0, 0, 0, "");

        fywflcode = sqsx.getFywflcode();

        StringBuffer errorMsg = new StringBuffer();
        if (fzzrs > 0){
            Result result = busService.ybmOrJcykXpByAuto(hcyXpVo, sqsxid, sqsx, SpcyConstant.HCY_SSK_ZZ, fusertype, zytc, hbqy, fssqy, fywflcode, kssj, jssj, fzzrs, fzyrs, fybrs, fxptjid);
            if (!result.isSuccess()) {
                errorMsg.append(result.getMessage());
            }
        }

        if (fzyrs > 0){
            Result result = busService.ybmOrJcykXpByAuto(hcyXpVo, sqsxid, sqsx, SpcyConstant.HCY_SSK_ZY, fusertype, zytc, hbqy, fssqy, fywflcode, kssj, jssj, fzzrs, fzyrs, fybrs, fxptjid);
            if (!result.isSuccess()) {
                errorMsg.append(result.getMessage());
            }
        }

        if (fybrs > 0){
            Result result = busService.ybmOrJcykXpByAuto(hcyXpVo, sqsxid, sqsx, SpcyConstant.HCY_SSK_YBK, fusertype, zytc, hbqy, fssqy, fywflcode, kssj, jssj, fzzrs, fzyrs, fybrs, fxptjid);
            if (!result.isSuccess()) {
                errorMsg.append(result.getMessage());
            }
        }

        /** 查员库随机-药检所人员-指派 */
        busService.yjsrySjXpByFxptjid(hcyXpVo, sqsxid, sqsx, fusertype, zytc, hbqy, fssqy, fywflcode, kssj, jssj, fzzrs, fzyrs, fybrs, fxptjid);

        if (!StringPatternUtils.verifryIsEmptyStringBuffer(errorMsg)){
            return HttpResult.error(errorMsg.toString());
        }

        return HttpResult.ok("操作成功");
    }

    @Log(title = "验证是否存在选派人员中已经存在药检所人员")
    @ApiOperation(value = "验证是否存在选派人员中已经存在药检所人员")
    @GetMapping(value = "verifyCzYjs")
    public HttpResult verifyCzYjs(@RequestParam(value = "sqsxid",defaultValue = "") String sqsxid){
        if (StringUtils.isBlank(sqsxid)){
            return HttpResult.error("参数为空！");
        }

        return HttpResultVo.HttpResultGet(spcySqsxXpjlMapper.selectExistsYjsryListBySqsxId(
                sqsxid,
                SpcyConstant.XPJL_SFTYXP_YES,
                SpcyConstant.XPJL_SFTYXP_WQY,
                SpcyConstant.HCY_SFYJSRY_YES).size());
    }

    /** ******************************************* [2024-03-20] **************/

    @Log(title = "查询报名计划基本信息-分页查询")
    @ApiOperation(value = "查询报名计划基本信息-分页查询")
    @GetMapping(value = "queryBmjbxxPageList")
    public HttpResult queryBmjbxxPageList(SpcySqsxYbmjbxx query, PageVo pageVo){

        Page<SqsxYbmjbxxVo> page = new Page(pageVo.getPageNo(), pageVo.getPageSize());

        Page<SqsxYbmjbxxVo> pageList = spcySqsxYbmjlMapper.getYbmjbxxJBmjhPageList(page, query);
        return HttpResult.ok(pageList);
    }

//    @Log(title = "查询报名计划基本信息列表-根据申请事项id")
//    @ApiOperation(value = "查询报名计划基本信息列表-根据申请事项id")
    @GetMapping(value = "queryBmjbxxListBySqsxId")
    public HttpResult queryBmjbxxListBySqsxId(@RequestParam(value = "sqsxid",defaultValue = "")String sqsxid){
        if (StringUtils.isBlank(sqsxid)){
            throw new BusinessException("申请事项参数为空！");
        }
        /*String sqsxbm = spcySqsxBaiscService.getYwflCodeBySqsxId(sqsxid);

        LambdaQueryWrapper<SpcySqsxYbmjbxx> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(SpcySqsxYbmjbxx::getFsqsxbm, sqsxbm);
        queryWrapper.orderByDesc(SpcySqsxYbmjbxx::getFfbrq);
        List<SpcySqsxYbmjbxx> list = spcySqsxYbmjbxxService.list(queryWrapper);*/
        return HttpResultVo.HttpResultList(null);
    }

    @Log(title = "查询报名计划明细列表-根据申请事项id")
    @ApiOperation(value = "查询报名计划明细列表-根据申请事项id")
    @GetMapping(value = "queryBmjhmxlbBySqsxId")
    public HttpResult queryBmjhmxlbBySqsxId(@RequestParam(value = "sqsxid",defaultValue = "")String sqsxid,
                                            @RequestParam(value = "kssj",defaultValue = "")String kssj,
                                            @RequestParam(value = "jssj",defaultValue = "")String jssj){
        if (StringUtils.isBlank(sqsxid)){
            throw new BusinessException("申请事项参数为空！");
        }

        LambdaQueryWrapper<SpcySqsxYbmjh> queryWrapper = new LambdaQueryWrapper<>();
        /*String sqsxbm = spcySqsxBaiscService.getYwflCodeBySqsxId(sqsxid);
        queryWrapper.eq(SpcySqsxYbmjh::getFsqsxbm, sqsxbm);*/
        queryWrapper.eq(SpcySqsxYbmjh::getSqsxid, sqsxid);

        /*if (DateConversionUtils.isValidDateStringYmd(kssj)){
            queryWrapper.le(SpcySqsxYbmjh::getFcykssj, DateConversionUtils.convertStringToDateYmd(kssj));
        }
        if (DateConversionUtils.isValidDateStringYmd(jssj)){
            queryWrapper.ge(SpcySqsxYbmjh::getFcyjssj, DateConversionUtils.convertStringToDateYmd(jssj));
        }*/

        queryWrapper.orderByDesc(SpcySqsxYbmjh::getFfbrq);
        List<SpcySqsxYbmjh> list = spcySqsxYbmjhService.list(queryWrapper);
        return HttpResultVo.HttpResultList(list);
    }

    @Log(title = "查询报名计划明细列表-根据报名基本信息id")
    @ApiOperation(value = "查询报名计划明细列表-根据报名基本信息id")
    @GetMapping(value = "queryBmjhListByJbxxid")
    public HttpResult queryBmjhListByJbxxid(@RequestParam(value = "id",defaultValue = "")String id){

        List<SpcySqsxYbmjh> list = spcySqsxYbmjhService.list(new LambdaQueryWrapper<SpcySqsxYbmjh>()
                .eq(SpcySqsxYbmjh::getFbmjbxxid, id)
                .orderByAsc(SpcySqsxYbmjh::getFfbrq));
        return HttpResultVo.HttpResultList(list);
    }

    @Log(title = "报名基本信息-添加")
    @ApiOperation(value = "报名基本信息-添加")
    @PostMapping(value = "addBmjbxx")
    public HttpResult addBmjbxx(@RequestBody SpcySqsxYbmjbxx bean){

        if (StringUtils.isBlank(bean.getFjhmc())){
            throw new BusinessException("计划名称为空！");
        }

        if (StringUtils.isBlank(bean.getFjcylx())){
            throw new BusinessException("检查类型为空！");
        }

        if (bean.getFbmksrq() == null || bean.getFbmjsrq() == null){
            throw new BusinessException("报名日期不能为空！");
        }

        bean.setFssks(GetCurrentUserUtils.getCurrentUserOrgName());
        bean.setFsqsxbm(SpcyConstant.getYwflByDeptName(bean.getFssks()));
        bean.setFbmzt(SpcyCommonConstant.SQSX_YBMJH_BMZT_BMZ);
        bean.setFfbrq(new Date());
        bean.setFfbrxm(GetCurrentUserUtils.getCurrentUserName());
        spcySqsxYbmjbxxService.save(bean);

        return HttpResultVo.HttpResultSave(bean.getId(), "保存成功");
    }

    @Log(title = "报名基本信息-更新")
    @ApiOperation(value = "报名基本信息-更新")
    @PostMapping(value = "updateBmjbxx")
    public HttpResult updateBmjbxx(@RequestBody HashMap<String,String> buffer) throws InvocationTargetException, IllegalAccessException {
        String id = buffer.get("id");
        if (StringUtils.isBlank(id)){
            throw new BusinessException("参数为空！");
        }

        SpcySqsxYbmjbxx updateBean = spcySqsxYbmjbxxService.getById(id);
        if (updateBean == null){
            throw new BusinessException("没有相匹配数据！");
        }

        SpcySqsxYbmjbxx oldBean = updateBean;

        ConvertUtils.register(new DateConvert(), java.util.Date.class);
        // 自动完成页面到bean的数据对接
        BeanUtils.populate(updateBean, buffer);


        /** 更新计划 */
        boolean isUpdateJh = false;
        SpcySqsxYbmjh updateJh = new SpcySqsxYbmjh();
        if (updateBean.getFbmksrq() != null){
            updateJh.setFbmksrq(updateBean.getFbmksrq());
            isUpdateJh = true;
        }
        if (updateBean.getFbmjsrq() != null) {
            updateJh.setFbmjsrq(updateBean.getFbmjsrq());
            isUpdateJh = true;
        }
        if (StringUtils.isNotBlank(updateBean.getFjcylx())) {
            updateJh.setFjcylx(updateBean.getFjcylx());
            isUpdateJh = true;
        }

        updateBean.setUpdateTime(new Date());
        updateBean.setUpdateBy(GetCurrentUserUtils.getCurrentUserAccount());
        spcySqsxYbmjbxxService.updateById(updateBean);

        if (isUpdateJh) {
            LambdaUpdateWrapper<SpcySqsxYbmjh> updateWrapperJh = new LambdaUpdateWrapper<>();
            updateWrapperJh.eq(SpcySqsxYbmjh::getFbmjbxxid, id);

            spcySqsxYbmjhService.update(updateJh, updateWrapperJh);
        }

        return HttpResultVo.HttpResultSave(id, "保存成功");
    }

    @Log(title = "报名基本信息-结束报名")
    @ApiOperation(value = "报名基本信息-结束报名")
    @GetMapping(value = "bmjbxxByJsbm")
    public HttpResult bmjbxxByJsbm(@RequestParam(value = "id",defaultValue = "")String id){
        if (StringUtils.isBlank(id)){
            throw new BusinessException("参数为空！");
        }

        // 结束报名基本信息
        LambdaUpdateWrapper<SpcySqsxYbmjbxx> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.eq(SpcySqsxYbmjbxx::getId, id);

        SpcySqsxYbmjbxx updateJbxx = new SpcySqsxYbmjbxx();
        updateJbxx.setFbmzt(SpcyCommonConstant.SQSX_YBMJH_BMZT_YJS);
        spcySqsxYbmjbxxService.update(updateJbxx, updateWrapper);

        // 结束计划
        LambdaUpdateWrapper<SpcySqsxYbmjh> updateWrapperJh = new LambdaUpdateWrapper<>();
        updateWrapperJh.eq(SpcySqsxYbmjh::getFbmjbxxid, id);

        SpcySqsxYbmjh updateJh = new SpcySqsxYbmjh();
        updateJh.setFbmzt(SpcyCommonConstant.SQSX_YBMJH_BMZT_YJS);
        spcySqsxYbmjhService.update(updateJh, updateWrapperJh);

        return HttpResult.ok("保存成功");
    }

    @Log(title = "报名计划明细-添加")
    @ApiOperation(value = "报名计划明细-添加")
    @PostMapping(value = "addBmjhmx")
    public HttpResult addBmjhmx(@RequestBody SpcySqsxYbmjh bean){
        if (StringUtils.isBlank(bean.getFbmjbxxid())){
            throw new BusinessException("参数为空！");
        }

        if (StringUtils.isBlank(bean.getFjcbmrwmc())){
            throw new BusinessException("检查报名任务名称为空！");
        }

        if (bean.getFcykssj() == null || bean.getFcyjssj() == null){
            throw new BusinessException("检查时间不能为空！");
        }

        SpcySqsxYbmjbxx jbxx = spcySqsxYbmjbxxService.getById(bean.getFbmjbxxid());
        if (jbxx == null){
            throw new BusinessException("没有相匹配的数据！");
        }

        int jcts =  (int) DateUtil.between(bean.getFcykssj(), bean.getFcyjssj(), DateUnit.DAY) + 1;
        bean.setFjcts(jcts);

        bean.setFbmksrq(jbxx.getFbmksrq());
        bean.setFbmjsrq(jbxx.getFbmjsrq());
        bean.setFjcylx(jbxx.getFjcylx());
        bean.setFbmzt(jbxx.getFbmzt());
        bean.setFssks(jbxx.getFssks());
        bean.setFsqsxbm(jbxx.getFsqsxbm());

        if (bean.getFbmzzrs() == null) {
            bean.setFzzrs(jbxx.getFzzrs());
        }
        if (bean.getFzyrs() == null) {
            bean.setFzyrs(jbxx.getFzyrs());
        }
        if (bean.getFybrs() == null) {
            bean.setFybrs(jbxx.getFybrs());
        }

        bean.setFbmzzrs(0);
        bean.setFbmzyrs(0);
        bean.setFbmybrs(0);

        bean.setFfbrq(new Date());
        bean.setFfbrid(GetCurrentUserUtils.getCurrentUserId());
        bean.setFfbrxm(GetCurrentUserUtils.getCurrentUserName());
        spcySqsxYbmjhService.save(bean);

        return HttpResultVo.HttpResultSave(bean.getId(), "保存成功");
    }

    @Log(title = "报名计划明细-更新")
    @ApiOperation(value = "报名计划明细-更新")
    @PostMapping(value = "updateBmjh")
    public HttpResult updateBmjh(@RequestBody HashMap<String,String> buffer) throws InvocationTargetException, IllegalAccessException {
        String id = buffer.get("id");
        if (StringUtils.isBlank(id)){
            throw new BusinessException("参数为空！");
        }

        SpcySqsxYbmjh updateBean = spcySqsxYbmjhService.getById(id);
        if (updateBean == null){
            throw new BusinessException("没有相匹配数据！");
        }

        ConvertUtils.register(new DateConvert(), java.util.Date.class);
        // 自动完成页面到bean的数据对接
        BeanUtils.populate(updateBean, buffer);

        if (updateBean.getFcykssj() != null && updateBean.getFcyjssj() != null) {
            int jcts = (int) DateUtil.between(updateBean.getFcykssj(), updateBean.getFcyjssj(), DateUnit.DAY) + 1;
            updateBean.setFjcts(jcts);
        }

        updateBean.setUpdateTime(new Date());
        updateBean.setUpdateBy(GetCurrentUserUtils.getCurrentUserAccount());
        spcySqsxYbmjhService.updateById(updateBean);

        return HttpResultVo.HttpResultSave(id, "保存成功");
    }

    @Log(title = "删除报名基本信息")
    @ApiOperation(value = "删除报名基本信息")
    @DeleteMapping(value = "deleteBmjbxx")
    public HttpResult deleteBmjbxx(@RequestParam(value = "id",defaultValue = "")String id){
        if (StringUtils.isBlank(id)){
            return HttpResult.error("参数为空！");
        }
        spcySqsxYbmjbxxService.removeById(id);

        List<SpcySqsxYbmjh> jhList = spcySqsxYbmjhService.list(new LambdaQueryWrapper<SpcySqsxYbmjh>()
                .eq(SpcySqsxYbmjh::getFbmjbxxid, id));
        spcySqsxYbmjhService.remove(new LambdaQueryWrapper<SpcySqsxYbmjh>()
                .eq(SpcySqsxYbmjh::getFbmjbxxid, id));
        for (int i = 0; i < jhList.size(); i++) {
            spcySqsxYbmjlService.remove(new LambdaQueryWrapper<SpcySqsxYbmjl>()
                    .eq(SpcySqsxYbmjl::getFbmjhid, jhList.get(i).getId()));
        }

        return HttpResult.ok("删除成功");
    }

    @Log(title = "删除报名计划明细")
    @ApiOperation(value = "删除报名计划明细")
    @DeleteMapping(value = "deleteBmjbmx")
    public HttpResult deleteBmjbmx(@RequestParam(value = "id",defaultValue = "")String id){
        if (StringUtils.isBlank(id)){
            return HttpResult.error("参数为空！");
        }

        spcySqsxYbmjhService.removeById(id);

        spcySqsxYbmjlService.remove(new LambdaQueryWrapper<SpcySqsxYbmjl>()
                .eq(SpcySqsxYbmjl::getFbmjhid, id));

        return HttpResult.ok("删除成功");
    }

    /**
     * 2024-03-26
     */
    @Log(title = "将申请事项-列入计划")
    @ApiOperation(value = "将申请事项-列入计划")
    @PostMapping(value = "lrbmjhBySqsx")
    public HttpResult lrbmjhBySqsx(@RequestBody SpcySqsxYbmjh bean){
        if (StringUtils.isBlank(bean.getSqsxid())){
            throw new BusinessException("申请事项参数为空！");
        }
        SpcySqsxBasic sqsx = spcySqsxBaiscService.selectSqsxSxxxById(bean.getSqsxid());
        if (sqsx == null){
            throw new BusinessException("没有想匹配的数据！");
        }

        if (StringUtils.isNotBlank(sqsx.getFybmzt())) {
            return HttpResult.error("已经申请过了");
        }

        if (bean.getFcykssj() == null){
            return HttpResult.error("检查时间不能为空！");
        }
        if (bean.getFcyjssj() == null){
            return HttpResult.error("检查时间不能为空！");
        }
        if (StringUtils.isBlank(bean.getFjcdd())){
            return HttpResult.error("检查地点不能为空！");
        }
        LambdaUpdateWrapper<SpcySqsxBasic> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.eq(SpcySqsxBasic::getId, bean.getSqsxid());

        SpcySqsxBasic updateBean = new SpcySqsxBasic();
        if (sqsx.getFcykssj() == null || (!bean.getFcykssj().equals(sqsx.getFcykssj()))) {
            updateBean.setFcykssj(bean.getFcykssj());
        }
        if (sqsx.getFcyjssj() == null || (!bean.getFcyjssj().equals(sqsx.getFcyjssj()))) {
            updateBean.setFcyjssj(bean.getFcyjssj());
        }

        updateBean.setFjcdd(bean.getFjcdd());
        updateBean.setFjcyq(bean.getFjcyq());
        updateBean.setFsxjclx(JcydjbConstant.getJcylxByYwflcode(sqsx.getFywflcode()));
        updateBean.setFybmzt(SpcyCommonConstant.SQSX_YBMZT_YSQ);

        /*spcySqsxBaiscService.update(updateBean, updateWrapper);

        spcySqsxXpjlService.syncUpdateXpjlGzsjBySqsx(bean.getSqsxid(), bean.getFcykssj(), bean.getFcyjssj());*/
        spcyYbmjhService.lrbmjhBySqsx(bean, updateBean, updateWrapper);

        return HttpResult.ok("操作成功");
    }

    @Log(title = "汇总检查计划-查询列表")
    @ApiOperation(value = "汇总检查计划-查询列表")
    @GetMapping(value = "hzjcjhList")
    public HttpResult hzjcjhList(){

        List<SpcySqsxBasic> list = spcySqsxBaiscService.getHzjcjhSqsxList(SpcyCommonConstant.SQSX_YBMZT_YSQ);
        return HttpResultVo.HttpResultList(list);
    }

    @Log(title = "汇总检查计划-添加/发布")
    @ApiOperation(value = "汇总检查计划-添加/发布")
    @PostMapping(value = "hzjcjhAdd")
    public HttpResult hzjcjhAdd(@RequestBody SpcySqsxYbmjbxx bean){

        List<SpcySqsxBasic> sqsxList = spcySqsxBaiscService.getHzjcjhSqsxList(SpcyCommonConstant.SQSX_YBMZT_YSQ);
        if (CollectionUtil.isEmpty(sqsxList)){
            throw new BusinessException("没有可汇总的检查计划！");
        }

        if (StringUtils.isBlank(bean.getFjhmc())){
            throw new BusinessException("计划名称为空！");
        }

        if (bean.getFbmksrq() == null || bean.getFbmjsrq() == null){
            throw new BusinessException("报名日期不能为空！");
        }

        bean.setId(GetUuIdUtils.ReplaceUuId());
        bean.setFssks(GetCurrentUserUtils.getCurrentUserOrgName());
        bean.setFsqsxbm(SpcyConstant.getYwflByDeptName(bean.getFssks()));


        /*if (StringUtils.isNotBlank(bean.getFbmzt())
                && bean.getFbmzt().equals(SpcyCommonConstant.SQSX_YBMJH_BMZT_BMZ)){
            bean.setFbmzt(SpcyCommonConstant.SQSX_YBMJH_BMZT_BMZ);
            bean.setFfbrq(new Date());
            bean.setFfbrxm(GetCurrentUserUtils.getCurrentUserName());
        }else {*/
        bean.setFbmzt(SpcyCommonConstant.SQSX_YBMJH_BMZT_WKS);


        String fjcylx = "";
        List<SpcySqsxYbmjh> jhList = new ArrayList<>();
        for (SpcySqsxBasic sqsx : sqsxList){
            if (StringUtils.isBlank(fjcylx)){
                fjcylx = sqsx.getFsxjclx();

            }else if (!fjcylx.contains(sqsx.getFsxjclx())){
                fjcylx += "," + sqsx.getFsxjclx();
            }

            jhList.add(initHzjcjh(bean.getId(), bean, sqsx));
        }

        bean.setFjcylx(fjcylx);
        /*spcySqsxYbmjbxxService.save(bean);

        spcySqsxYbmjhService.saveBatch(jhList);

        spcySqsxBaiscService.updateHzjcjhSqsxByYbmzt();*/
        spcyYbmjhService.hzjcjhAdd(bean, jhList);

        return HttpResultVo.HttpResultSave(bean.getId(), "保存成功");
    }

    /** 初始化-汇总检查计划-内容 */
    private SpcySqsxYbmjh initHzjcjh(String fbmjbxxid, SpcySqsxYbmjbxx jbxx, SpcySqsxBasic sqsx){
        SpcySqsxYbmjh bean = new SpcySqsxYbmjh();
        bean.setFbmjbxxid(fbmjbxxid);
        int jcts =  (int) DateUtil.between(sqsx.getFcykssj(), sqsx.getFcyjssj(), DateUnit.DAY) + 1;
        bean.setFjcts(jcts);

        bean.setFbmksrq(jbxx.getFbmksrq());
        bean.setFbmjsrq(jbxx.getFbmjsrq());

        bean.setFssks(sqsx.getFywflname());
        bean.setFsqsxbm(sqsx.getFywflcode());
        bean.setFjcyq(sqsx.getFjcyq());
        bean.setFjcdd(sqsx.getFjcdd());
        bean.setFjcylx(sqsx.getFsxjclx());
        bean.setFcykssj(sqsx.getFcykssj());
        bean.setFcyjssj(sqsx.getFcyjssj());
        bean.setSqsxid(sqsx.getId());

        bean.setFzzrs(0);
        bean.setFzyrs(0);
        bean.setFybrs(0);
        bean.setFbmzzrs(0);
        bean.setFbmzyrs(0);
        bean.setFbmybrs(0);

        /*if (jbxx.getFbmzt().equals(SpcyCommonConstant.SQSX_YBMJH_BMZT_BMZ)){
            bean.setFbmzt(SpcyCommonConstant.SQSX_YBMJH_BMZT_BMZ);
            bean.setFfbrq(new Date());
            bean.setFfbrxm(GetCurrentUserUtils.getCurrentUserName());

        }else {*/
        bean.setFbmzt(SpcyCommonConstant.SQSX_YBMJH_BMZT_WKS);

        bean.setFfbrq(new Date());
        bean.setFfbrid(GetCurrentUserUtils.getCurrentUserId());
        bean.setFfbrxm(GetCurrentUserUtils.getCurrentUserName());
        bean.setCreateTime(new Date());
        bean.setCreateBy(GetCurrentUserUtils.getCurrentUserAccount());

        return bean;
    }

    @Log(title = "发布报名计划")
    @ApiOperation(value = "发布报名计划")
    @GetMapping(value = "fbbmjhjbxx")
    public HttpResult fbbmjhjbxx(@RequestParam(value = "id",defaultValue = "")String id){
        if (StringUtils.isBlank(id)){
            return HttpResult.error("参数为空！");
        }
        spcyYbmjhService.fbbmjhjbxx(id);

        return HttpResult.ok("发布成功");
    }

    @Log(title = "作废报名计划")
    @ApiOperation(value = "作废报名计划")
    @PostMapping(value = "zfbmjhjbxx")
    public HttpResult zfbmjhjbxx(@RequestBody SpcySqsxYbmjbxx bean){
        if (StringUtils.isBlank(bean.getId())){
            return HttpResult.error("参数为空！");
        }
        if (StringUtils.isBlank(bean.getFbz())){
            return HttpResult.error("作废理由为空！");
        }

        spcyYbmjhService.zfbmjhjbxx(bean);

        return HttpResult.ok("作废成功");
    }



}
